package com.shen.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public final class BaseDaoImpl extends HibernateDaoSupport implements BaseDao{
	
	/*
	 * (non-Javadoc)
	 * @see com.shen.dao.BaseDao#find(java.lang.String)
	 */
	public List<?> find(String hql) {
		return getHibernateTemplate().find(hql);
	}

	/*
	 * (non-Javadoc)
	 * @see com.shen.dao.BaseDao#find(java.lang.String, java.lang.Object[])
	 */
	public List<?> find(String hql,Object[] params) {
		return this.getHibernateTemplate().find(hql, params);
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.shen.dao.BaseDao#unique(java.lang.Class, java.io.Serializable)
	 */
	public Object unique(Class<?> entityClass,Serializable id){
		//注意get和load方法的区别。延迟加载
		return this.getHibernateTemplate().get(entityClass, id);
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.shen.dao.BaseDao#save(java.lang.Object)
	 */
	public void save(Object entity) {
		getHibernateTemplate().save(entity);
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.shen.dao.BaseDao#save(java.lang.Object, boolean)
	 */
	public void save(Object entity, boolean refresh) {
		getHibernateTemplate().save(entity);
		if (refresh) {
			getHibernateTemplate().flush();
			getHibernateTemplate().refresh(entity);
		}
	}
	
	public void findByQbc(Class<?> clazz){
		Criteria criteria = getSession().createCriteria(clazz);
//		criteria.add(Expression.eq("", ""));
		criteria.add(Restrictions.eq("", ""));
		criteria.list();
		
	}
}
